package com.cloud.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Component;

import com.cloud.core.BaseDao;
import com.cloud.dao.LableBean;
import com.cloud.dao.MyPatientBean;
import com.cloud.dao.PatientBean;

/**
 * 1Cloud1
 * @author Administrator
 * @since 2015-12-7
 * @version 1.0 
 */
@Component("MyPatientDao")
public class MyPatientDao extends BaseDao {
	
	public List<PatientBean> getMyPatientList(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		List<PatientBean> beanList = null;
		try {
			beanList = session.selectList("mypatient.list", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public List<PatientBean> getMyPatientListByLable(LableBean bean){
		SqlSession session = super.getInstance(true);
		List<PatientBean> beanList = null;
		try {
			beanList = session.selectList("mypatient.listbylable", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			session.close();
		}
		return beanList;
	}
	
	public void addMyPatient(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		try {
			session.insert("mypatient.insert", bean);
		} catch (Exception e) {
			
		} finally {
			session.close();
		}
	}
	
	public void updateMyPatient(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		session.update("mypatient.update", bean);
		session.close();
	}
	
	public void deletePatientFromPro(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		session.update("mypatient.deletePatientFromPro", bean);
		session.close();
	}
	
	public void deleteMyPatient(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		session.delete("mypatient.delete", bean);
		session.close();
	}
	
	public Integer listCount(MyPatientBean bean){
		SqlSession session = super.getInstance(true);
		Integer count = session.selectOne("mypatient.listcount", bean);
		session.close();
		return count;
	}
	
	public String getHosByPatient(PatientBean bean){
		SqlSession session = super.getInstance(true);
		Object obj = null;
		try {
			obj = session.selectOne("mypatient.getHosByPatient", bean);
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		} finally {
			session.close();
		}
		return obj == null ? "" : obj.toString();
	}
	
	public Integer getPatientProCount(PatientBean bean){
		SqlSession session = super.getInstance(true);
		Integer count = session.selectOne("mypatient.getPatientProCount", bean);
		session.close();
		return count;
	}
}
